#!/bin/bash
# 生成定时任务
source /etc/profile

path=$(cd $(dirname $0);pwd)
chmod +x ${path}/*/*.sh ${path}/*/*.py ${path}/*.sh ${path}/*.py
day=$(date +"%Y%m%d")
tm=$(date -d "+1 days" +"%Y%m%d")
hadoo fs -mkdir -p /log/nas/${day} /logs/nas/${day} /log/nas/${tm} /logs/nas/${tm}
#create table
hive -e "CREATE DATABASE IF NOT EXISTS formatlog;"
wait
hive -e "use formatlog;create external table IF NOT EXISTS nas_tracking_format_hour(cid string,sid string,ep string,referer string,originalUrl string,ip string,eventID int,regionID int,countryID int,country string,areaID int,area string,region string,cityID int,city string,countyID int,county string,time bigint,timeY int,timeM int,timeD int,timeH int,color string,resolution string,userAgent string,java string,flash string,lang string,se string,NASID string,cookie string,ispID string,isp string,os string,platform string,browser string,version string,refererType string,query string,device string,customize int,session string,isNew int,sis string,sisurl string,ispay string,os_type string,device_type string) partitioned by(day int,hour int) LOCATION '/user/work/trackingFormatLog'"

cat > ${path}/crontab_job_list <<EOF
# mkdir daily nas log
35 9 * * * ${path}/format_log/mkdir_daily_log.sh > ${path}/format_log/mkdir_daily_log.log 2>&1
# format hour log
4 */1 * * * ${path}/hour_crontab_job.sh > ${path}/hour_crontab_job.log 2>&1
# clean tmp file
35 9 * * * ${path}/clean_job_tmp_file.sh > ${path}/clean_job_tmp_file.log 2>&1

EOF
wait
crontab ${path}/crontab_job_list
wait
echo `crontab -l`